package com.wechat.order.util;

import com.wechat.order.enums.CodeEnum;

/**
 * Created by zzy on 2017/12/19.
 */
public class EnumUtil {

    /**
     * 通过code获取对应枚举
     * @param code
     * @param enumClass
     * @param <T>
     * @return
     */
    public static <T extends CodeEnum> T getByCode(Integer code, Class<T> enumClass){
        for (T each: enumClass.getEnumConstants()) {
            if(code.equals(each.getCode())){
                return each;
            }
        }
        return null;
    }
}
